package com.zwh.rabbitmq.basic.exchange;

import java.util.HashMap;
import java.util.Map;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.HeadersExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * header 交换机， 同direct类似，消息header属性值相等匹配
 * @author monkey
 * @date 2020/11/3 10:59
 **/
@Configuration
public class HeadersExchangeConfig {
    @Bean
    public HeadersExchange headersExchange(){
        return new HeadersExchange("myHeaders");
    }

    @Bean
    public Queue headersQueue1() {
        Queue queue=new Queue("headersqueue1");
        return queue;
    }

    @Bean
    public Binding headersBinding1(){
        Map<String,Object> headers = new HashMap<>(1);
        headers.put("type","secondKill");
        // 绑定header头部属性值 type=secondKill
        Binding binding= BindingBuilder.bind(headersQueue1()).to(headersExchange())
                .whereAll(headers).match();
        return binding;
    }
}
